package com.com.effectivejava.generics.examples2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by User on 29/06/2015.
 */
public class BoxDemo {

    public static <U> void addBox(U u , List<Box<U>> boxes)
    {
        Box<U> box = new Box<>();
        box.set(u);
        boxes.add(box);
    }

    public static <U> void outputBoxes(List<Box<U>> boxes)
    {
        int counter = 0;
        for(Box<U> box : boxes)
        {
            U boxContents = box.get();
            System.out.println("boxContents.toString() = " + boxContents.toString());
        }
    }

    public static void main(String[] args) {
       List<Box<String>> boxes = new ArrayList<>();
        addBox("A" , boxes);
        addBox("B" , boxes);
        addBox("C" , boxes);
        outputBoxes(boxes);

        List<Box<Integer>> boxesInteger = new ArrayList<>();
        BoxDemo.<Integer>addBox(1 , boxesInteger);
        addBox(8 , boxesInteger);
        addBox(3 , boxesInteger);
        outputBoxes(boxesInteger);
    }
}
